<?php ob_start(); ?>
<?php
$scriptWindowMsg = "
    $(function() {
        $('a#close').click(function() {
            window.close();
        });
    });";
$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
?>
<style>
    #wrapper-report {
        height: auto;
        margin: auto;
        width: auto;
    }
    .title-tbl {
        background-color: #dedddd;
        font-size: 13px;
        font-weight: bold;
    }
    thead {
      background-color: #dedddd;
    }
    .tbl-broking td {
        border-bottom: 1px solid #333333;
        border-left: 1px solid;
        border-right: 1px solid #333333;
        height: 30px;
    }
    .td-payment-r {
        width: 100px;
    }
    td {
        text-align: center;
        vertical-align: middle;
    }
    .tbl-broking tr {
        height: 30px;
        margin: 0;
        padding: 0;
    }
    .tbl-broking {
        border-left: 1px solid #333333;
        border-top: 1px solid #333333;
        height: auto;
        margin: 0;
        padding: 0;
        table-layout: fixed;
        width: 100%;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        font-size: 0;
        height: 0;
        visibility: hidden;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        height: 0;
        visibility: hidden;
    }
    .wrapper-table {
        height: auto;
        margin: 13px 0 0;
        padding: 0;
        width: 100%;
    }
    .clearfix {
        display: block;
    }
    .title-body-content {
        color: #A0002A;
        font-size: 17px;
        font-weight: bold;
        height: auto;
        margin: 0 0 0;
        padding: 0;
        text-align: center;
        width: 100%;
    }
    .wrapper-content-body {
        background-color: White;
        height: auto;
        margin: 0 0 60px;
        padding: 0 16px 0;
        width: 96.8%;
    }
    .wrapper-body {
        background-color: White;
        height: auto;
        margin: 0;
        padding: 10px 0 0;
        width: 100%;
    }
    .hightlight {
        background-color: yellow;
        font-weight: bold;
    }
    .line-content-tbl {
        font-size: 12px;
    }
</style>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="wrapper-table clearfix" style="overflow:auto; padding-bottom: 10px;">
    <table class="tbl-broking" border="1">
        <thead>
            <tr class="title-tbl" >
                <td><?php echo __('Reference#'); ?></td>
                <td><?php echo __('Due date'); ?></td>
                <td><?php echo __('Payer'); ?></td>
                <td><?php echo __('Payee'); ?></td>
                <td><?php echo __('Amount'); ?></td>
                <td><?php echo __('Exchange'); ?></td>
                <td><?php echo __('USD'); ?></td>
                <td><?php echo __('Paid'); ?></td>
                <td><?php echo __('Amount Paid'); ?></td>
                <td><?php echo __('Paid date'); ?></td>
                <td class="hightlight" style="text-align: right; padding-right:3px;"><?php echo __('Outstanding'); ?></td>
            </tr>
        </thead>
        <?php
        foreach ($paymentschedules AS $paymentschedule) {
            $checked = ($paymentschedule['Paymentschedule']['paid'] == '1') ? '&#10003;' : ' ';
            if($paymentschedule['Paymentschedule']['paid_date'] != '0000-00-00') {
                $paiddate = date('m/d/Y', strtotime($paymentschedule['Paymentschedule']['paid_date']));
            }else{
                $paiddate = '';
            }

            if($paymentschedule['Paymentschedule']['broker_date'] != '0000-00-00') {
                $paymentdate = date('m/d/Y', strtotime($paymentschedule['Paymentschedule']['broker_date']));
            }else{
                $paymentdate = '';
            }
            $usd = ($paymentschedule['Paymentschedule']['exchange'] > 0) ? '$ '. number_format($paymentschedule['Paymentschedule']['broker_amount'] / $paymentschedule['Paymentschedule']['exchange'],2): ' ';
            echo '
                    <tr class="line-content-tbl" >
                        <td>' . $paymentschedule['Paymentschedule']['refid_edit'] . '</td>
                        <td>' . $paymentdate . '</td>
                        <td>' . $paymentschedule['Paymentschedule']['payment_desc'] . '</td>
                        <td>' . $paymentschedule['Paymentschedule']['payee'] . '</td>
                        <td style="text-align:right; padding-right:5px">' . $paymentschedule['Paymentschedule']['currency'] . ' ' . number_format($paymentschedule['Paymentschedule']['broker_amount'],2) . '</td>
                        <td>' . $paymentschedule['Paymentschedule']['exchange'] . '</td>
                        <td style="text-align: right; padding-right:3px;">'
                            . $usd .
                        '</td>
                        <td>
                            ' . $checked . '
                        </td>
                        <td style="text-align:right; padding-right:5px" >'. $paymentschedule['Paymentschedule']['currency'] . ' ' .number_format($paymentschedule['Paymentschedule']['paid_amount'],2).'</td>
                        <td>'.$paiddate.'</td>
                        <td class="hightlight" style="text-align: right; padding-right:3px;">'.$paymentschedule['Paymentschedule']['currency'] . ' ' .number_format($paymentschedule['Paymentschedule']['broker_amount'] - $paymentschedule['Paymentschedule']['paid_amount'],2).'</td>
                    </tr>';
        }
        ?>
    </table>

</div>

<?php
    $HtmlCode= ob_get_contents();
    ob_end_flush();
    $file = '/home/johnso28/public_html/aihreinsurance.com/dompdf/aih/payment_schedules_report.html';
    $HtmlCode1 = str_replace('&#10003;', '<img src="img/tick.gif" alt="" />', $HtmlCode);
    file_put_contents($file, $HtmlCode1);
?>

<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" title="CLOSE" id="close"><?php echo __('CLOSE'); ?></a></div>
    </div>
</div>
<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/dompdf/dompdf.php?base_path=aih/&input_file=payment_schedules_report.html&paper=a4">Download PDF</a>
		&nbsp; | &nbsp;
		<?php echo $this->Html->link('Download Excel', '/phpexcel/paymentschedules.php?ids=' . $ids, null, array()); ?>
    </div>
</div>